Trapping Rain Water
Hard
Question
Given a list of non-negative integers representing the heights of walls, calculate the total amount of water that can be trapped after a rainfall.
Input: walls = [4, 2, 0, 3, 2, 3, 1]
Output: 5
Input: walls = [3, 1, 5, 2, 4, 2, 1]
Output: 4
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Given the walls map [0, 1, 0, 2, 0, 1], how much water can be trapped after rain?
1 unit of water
2 units of water
3 units of water
4 units of water
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.